<?php
ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\service\settlement\Settlement;
use Doraemon\amqp\Queue;

$billDate = date('Y-m', strtotime('-1 months'));
if (isset($argv[1])) {//格式 2018-04
    $month = $argv[1];
    $billDate = $month;
}
try {
    $res = Settlement::sysCreateBills($billDate);
    if ($res) {
        echo '生成' . $billDate . '账单成功';
    } else {
        echo '生成' . $billDate . '账单失败';
        Queue::insertQueue("queue/Wechatnotice/toTag", [
            "totag"=>\Biz\pockets\constInterface\BizWechatTagConfig::TAG_BIZ_RD_SYSTEM,
            "content" => "生成" . $billDate . "账单失败:#res:" . $res
        ], Queue::QUEUE_BIZ);
    }
} catch (Exception $e) {
    echo '生成' . $billDate . '账单失败';
    Queue::insertQueue("queue/Wechatnotice/toTag", [
        "totag"=>\Biz\pockets\constInterface\BizWechatTagConfig::TAG_BIZ_RD_SYSTEM,
        "content" => "生成" . $billDate . "账单失败:#msg:" . $e->getMessage() . "#file:" . $e->getFile() . "#line:" . $e->getLine()
    ], Queue::QUEUE_BIZ);
}
